/* 
  node 模拟接口
*/

const express = require("express");
const borderParser = require("body-parser");
const router = require("./router");
const session = require("express-session");

const app = express();

//设置跨域访问
app.all('*', function(req, res, next) {
   res.header("Access-Control-Allow-Origin", "*");
   res.header("Access-Control-Allow-Headers", "X-Requested-With");
   res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
   res.header("X-Powered-By",'3.2.1');
   res.header("Content-Type", "application/json;charset=utf-8");
   next();
});

app.use(session({
  secret: '#########',
  name: "sessionId",
  resave: false,
  saveUninitialized: false,
  cookie: { 
    macAge: 1000 * 60 * 60
  }
}))

// 挂在参数处理中间件 (post)
app.use(borderParser.urlencoded({
  extended: false
}));
app.use(borderParser.json())

app.use("/api2", router);

app.listen(3000, () => {
    console.log('running...');
});
